package com.awonsome.example.sms.controller;

import cn.hutool.json.JSONUtil;
import com.aliyun.dysmsapi20170525.models.QuerySendDetailsRequest;
import com.aliyun.dysmsapi20170525.models.QuerySendDetailsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.awonsome.common.sms.service.SmsService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author yangdejun
 * @date 2021/12/31 22:24
 */
@RestController
@RequestMapping(value = "/redis")
public class SmsTestController {

    private final RedisTemplate<String, String> redisTemplate;

    private final SmsService smsService;


    public SmsTestController(RedisTemplate<String, String> redisTemplate, SmsService smsService) {
        this.redisTemplate = redisTemplate;
        this.smsService = smsService;
    }

    @GetMapping(value = "/test")
    public void set() throws Exception {
        //redisTemplate.opsForValue().set("key", "value2");
        SendSmsRequest smsRequest = new SendSmsRequest();
        smsRequest.setSignName("合生活");
        smsRequest.setTemplateCode("SMS_230010483");
        smsRequest.setPhoneNumbers("18937671061");
        // 构建参数
        Map<String, Object> params = new HashMap<>();
        params.put("code", "54321");
        String s = JSONUtil.toJsonStr(params);
        smsRequest.setTemplateParam(s);
        SendSmsResponse sendSmsResponse = smsService.sendCode(smsRequest, "12345");
        System.out.println(sendSmsResponse.getBody().getCode());
        /*QuerySendDetailsRequest querySendDetailsRequest = new QuerySendDetailsRequest();
        querySendDetailsRequest.setPhoneNumber(smsRequest.getPhoneNumbers());
        QuerySendDetailsResponse querySendDetailsResponse = smsService.querySendDetails(querySendDetailsRequest);
        System.out.println(querySendDetailsResponse.getBody().getCode());
        System.out.println(querySendDetailsResponse.getBody().getRequestId());
        System.out.println(querySendDetailsResponse.getBody().getMessage());
        System.out.println(querySendDetailsResponse.getBody().getSmsSendDetailDTOs());
        System.out.println(querySendDetailsResponse.getBody().getTotalCount());*/
    }

    @GetMapping(value = "/check")
    public void check() throws Exception {

    }
}
